package com.nageoffer.shortlink.admin.toolkit;

import java.util.Random;

public final class RandomStringUtil {
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    private static final int LENGTH = 6;

    /**
     * 生成一个 6 位由字母和数字组成的随机字符串
     *
     * @return 随机生成的字符串
     */
    public static String generateRandomString() {
        StringBuilder stringBuilder = new StringBuilder(LENGTH);
        Random random = new Random();

        for (int i = 0; i < LENGTH; i++) {
            int index = random.nextInt(CHARACTERS.length()); // 从字符集里随机取一个字符
            stringBuilder.append(CHARACTERS.charAt(index));
        }

        return stringBuilder.toString();
    }
}
